//
//  ViewController.swift
//  Demo-13 获得罗盘方向
//
//  Created by quanhao huang on 2019/10/15.
//  Copyright © 2019 demo. All rights reserved.
//

import UIKit
import CoreMotion

class ViewController: UIViewController {

    var motionManager = CMMotionManager()
    @IBOutlet weak var directionLb: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        motionManager.startDeviceMotionUpdates(using: CMAttitudeReferenceFrame.xTrueNorthZVertical, to: OperationQueue.main) {
            (motion, error) in
            let yaw = motion!.attitude.yaw
            let yawDegrees = yaw * 180 / Double.pi
            self.directionLb.text = String(format: "Direction:%0.2f", yawDegrees);
            
        }
        
    }
    
}

